package org.wltea.analyzer.util;

import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.concurrent.ConcurrentHashMap;

public class FileHelper {
	
	private static ConcurrentHashMap<String, Long> timeMap = new ConcurrentHashMap<>();
	
	public static boolean isModified(String path) {
		try {
			URL url = FileHelper.class.getClassLoader().getResource(path);
			if(url==null||url.getProtocol().equals("jar")) {
				return true;
			}
			File file = new File(url.toURI());
			long currTime = file.lastModified();
			Long lastTimeObj = timeMap.get(path);
			long lastTime;
			timeMap.put(path, currTime);
			if(lastTimeObj==null) {
				return true;
			} else {
				lastTime = lastTimeObj.longValue();
				return currTime!=lastTime;
			}
		} catch (URISyntaxException e) {
			e.printStackTrace();
			return true;
		}
	}

}
